package com.zjitc.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/30 14:03
 * @description:
 */
@Component
public class Redis implements RedisCommand {
  @Autowired
  private JedisPool pool;

  @Autowired
  private Redis(JedisPool pool){
    this.pool = pool;
  }

  @Override
  public void set(String key, String value) {
    Jedis jedis=null;
    try {
      jedis = pool.getResource();
      jedis.set(key, value);
    }finally {
      if(jedis!=null){
        jedis.close();
      }
    }
  }
}
